﻿namespace EveKillboard.Data
{
    using System.Data.Entity;
    using Core;
    using Core.Base;
    using Core.Enums;
    using Core.Views;
    
    
    internal sealed class SqlDataContext : DbContext
    {
        public DbSet<Killmail> Killmails { get; set; }
        public DbSet<Item> Items { get; set; }
        public DbSet<Character> Characters { get; set; }
        public DbSet<Faction> Factions { get; set; }
        public DbSet<Alliance> Alliances { get; set; }
        public DbSet<Corporation> Corporations { get; set; }
        public DbSet<Location> Locations { get; set; }
        public DbSet<Involved> InvolvedParties { get; set; }
        public DbSet<KillmailItem> KillmailItems { get; set; }
        public DbSet<KillmailItemValue> KillmailItemValues { get; set; }
        public DbSet<ItemValue> ItemValues { get; set; }
        public DbSet<KillboardParameter> Parameters { get; set; }
        public DbSet<ItemName> ItemNames { get; set; }
        public DbSet<ShipSlot> ShipSlots { get; set; }
        public DbSet<SolarSystem> SolarSystems { get; set; }
        public DbSet<TopRegionMonth> TopRegionMonthKills { get; set; }
        public DbSet<TopRegionWeek> TopRegioWeekKills { get; set; }
        public DbSet<TopKillValue> TopKillsValue { get; set; }
        public DbSet<KillView> KillsView { get; set; }
        public DbSet<LossView> LossesView { get; set; }

        public DbSet<TopCharacterKillsMonthView> TopCharacterKillsMonthView { get; set; }
        public DbSet<TopCharacterKillsWeekView> TopCharacterKillsWeekView { get; set; }
        public DbSet<TopCharacterLossesMonthView> TopCharacterLossesMonthView { get; set; }
        public DbSet<TopCharactersLossesWeekView> TopCharactersLossesWeekView { get; set; }
        public DbSet<TopCharacterKillsValueMonthView> TopCharacterKillsValueMonthView { get; set; }

        public DbSet<TopCorporationKillsView> TopCorporationKillsView { get; set; }
        public DbSet<TopCorporationsKillsMonthView> TopCorporationsKillsMonthView { get; set; }
        public DbSet<TopCorporationsKillsWeekView> TopCorporationsKillsWeekView { get; set; }
        public DbSet<TopCorporationsLossesView> TopCorporationsLossesView { get; set; }
        public DbSet<TopCorporationsLossesMonthView> TopCorporationsLossesMonthView { get; set; }
        public DbSet<TopCorporationsLossesWeekView> TopCorporationsLossesWeekView { get; set; }

        public DbSet<AllianceStats> AlliancesStats { get; set; }
        public DbSet<CorporationStats> CorporationsStats { get; set; }
        public DbSet<CharacterStats> CharactersStats { get; set; }

        public DbSet<EveApiKeys> ApiKeys { get; set; }

        public DbSet<CorporationCharacterKillsMonthView> CorporationCharacterKillsMonthView { get; set; }
        public DbSet<CorporationCharacterLossesMonthView> CorporationCharacterLossesMonthView { get; set; }

        public DbSet<AllianceKillView> AllianceKillsView { get; set; }
        public DbSet<CorporationKillView> CorporationKillsView { get; set; }
        public DbSet<CharacterKillsView> CharacterKillsView { get; set; }

        public DbSet<CharacterShipsView> CharacterShipsView { get; set; }
        public DbSet<CharacterWeaponsView> CharacterWeaponsView { get; set; }
        public DbSet<CharacterShipGroupsKillsView> CharacterShipGroupsKillsView { get; set; }

        public DbSet<CharacterKills> CharacterKills { get; set; }
        public DbSet<CorporationKills> CorporationKills { get; set; }
        public DbSet<AllianceKills> AllianceKills { get; set; }

        public SqlDataContext()
            : base("KillboardDataContext")
        {
        }

        public SqlDataContext(string nameOrConnectionString) 
            : base(nameOrConnectionString)
        {
        }
        
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<EntityBase>()
                .Map<Character>(e => e.Requires("EntityType").HasValue((byte)EntityTypesEnum.Character))
                .Map<Corporation>(e => e.Requires("EntityType").HasValue((byte)EntityTypesEnum.Corporation))
                .Map<Alliance>(e => e.Requires("EntityType").HasValue((byte)EntityTypesEnum.Alliance))
                .Map<Faction>(e => e.Requires("EntityType").HasValue((byte)EntityTypesEnum.Faction));
        }
    }
}